package jstudy.gu.kit.http;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.stream.Collectors;

public class HttpResultParsers {
	public static IHttpResultParser<String> ofString() {
		return ofString(StandardCharsets.UTF_8);
	}

	public static IHttpResultParser<String> ofString(Charset charset) {
		IHttpResultParser<String> hr = in -> new BufferedReader(new InputStreamReader(in, charset)).lines()
				.collect(Collectors.joining(System.lineSeparator()));
		return hr;
	}

	public static IHttpResultParser<List<String>> ofList() {
		return ofList(StandardCharsets.UTF_8);
	}

	public static IHttpResultParser<List<String>> ofList(Charset charset) {
		IHttpResultParser<List<String>> hr = in -> new BufferedReader(new InputStreamReader(in, charset)).lines()
				.collect(Collectors.toList());
		return hr;
	}

}

 